<extend name="Public/base"/>
<block name="content">
    <form class="layui-form layui-form-pane1"  action="" method="post">
        <div class="layui-form-item">
            <label class="layui-form-label">链接标题</label>
            <div class="layui-input-block">
                <input type="text" name="title" lay-verify="required|title" required placeholder="请输入标题"
                       autocomplete="off" class="layui-input"><span id="linkmsg"></span>
            </div>
            <div>
                <label class="layui-form-label">链接地址</label>
                <div class="layui-input-block" style="margin-top: 10px; margin-bottom: 10px;">
                <input type="url" name="url" lay-verify="required|title"  required placeholder="请输入友情链接 注意友情链接以 http:// 开头哦"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">链接描述</label>
            <div class="layui-input-block">
                <textarea placeholder="请输入内容" class="layui-textarea" name="desc"></textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="*">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
        </div>
    </form>
</block>

<block name="js">
    <script src="__PUBLIC__/layui/layui.js"></script>
    <script>

        layui.use('form', function(){
            var data = {};
            var $ = layui.jquery;

            $('input[name="title"]').blur(function () {
                data.title = $('input[name="title"]').val();
                if(data.title==''||data.title==null) {
                    $('#linkmsg').html('<font color="red">很抱歉！链接标题不能为空</font>');
                    return false;
                }
                $.post("{:U('Link/checkTitle')}",data,function (e) {
                    if(e.code == 1){
                        $('#linkmsg').html('<font color="green">恭喜你！该标题可以使用</font>');
                    }else{
                        $('#linkmsg').html('<font color="red">很抱歉！该标题不可以使用哦</font>');
                    }
                });
            })
        })
    </script>
</block>
